import { random } from 'lodash';
import dayjs from 'dayjs';

const getAloneName = () => {
  return `${['周', '吴', '郑', '王'][random(0, 3)]}${
    ['甲', '乙', '丙', '丁'][random(0, 3)]
  }${random(1 - 9)}`;
};

const getPosLine = () => {
  const lines = [
    [
      [116.478935, 39.997761],
      [116.478939, 39.997825],
      [116.478912, 39.998549],
      [116.478912, 39.998549],
      [116.478998, 39.998555],
      [116.478998, 39.998555],
      [116.479282, 39.99856],
      [116.479658, 39.998528],
      [116.480151, 39.998453],
      [116.480784, 39.998302],
      [116.480784, 39.998302],
      [116.481149, 39.998184],
      [116.481573, 39.997997],
      [116.481863, 39.997846],
      [116.482072, 39.997718],
      [116.482362, 39.997718],
      [116.483633, 39.998935],
      [116.48367, 39.998968],
      [116.484648, 39.999861],
      [116.485148, 40.0001],
      [116.485648, 39.999861],
      [116.486848, 39.998861],
    ],
    [
      [115.478935, 38.997761],
      [115.478939, 38.997825],
      [115.478912, 38.998549],
      [115.478912, 38.998549],
      [115.478998, 38.998555],
      [115.478998, 38.998555],
      [115.479282, 38.99856],
      [115.479658, 38.998528],
      [115.480151, 38.998453],
      [115.480784, 38.998302],
      [115.480784, 38.998302],
      [115.481149, 38.998184],
      [115.481573, 38.997997],
      [115.481863, 38.997846],
      [115.482072, 38.997718],
      [115.482362, 38.997718],
      [115.483633, 38.998935],
      [115.48367, 38.998968],
      [115.484648, 38.999861],
      [115.485148, 39.0001],
      [115.485648, 38.999861],
      [115.486848, 38.998861],
    ],
  ];

  return lines[random(0, 1)];
};

export const getPosition = () => {
  const first = `116.47${random(1000, 9999)}`;
  const second = `39.99${random(1000, 9999)}`;

  return [Number(first), Number(second)];
};
const getItem = (item?: any) => {
  return {
    id: `${random(1000, 9999)}${random(1000, 9999)}`,
    name: getAloneName(),
    name1: getAloneName(),
    adress: ['北京', '重庆', '上海'][random(0, 2)],
    adress1: ['北京', '重庆', '上海'],
    sex: '男',
    age: `${random(30, 60)}`,
    time: `${dayjs()
      .subtract(random(1, 30), 'day')
      .format('YYYY-MM-DD HH:mm:ss')}`,
    time1: `${dayjs()
      .subtract(random(1, 30), 'day')
      .format('YYYY-MM-DD HH:mm:ss')}`,
    time2: `${dayjs()
      .subtract(random(1, 30), 'day')
      .format('YYYY-MM-DD HH:mm')}`,
    status: '进行中',
    phone: `188${random(1000, 9000)}${random(1000, 9000)}`,
    ment: ['行政部门', '技术部', '人事部'][random(0, 2)],
    number: random(1, 30),
    number1: random(10, 100),
    hour: random(1, 10),
    useType: ['客户用车', '部门用车'][random(0, 1)],
    carNo: `川A${random(10, 99)}${['K', 'D', 'L', 'N'][random(0, 3)]}${random(
      10,
      99
    )}`,
    position: getPosition(),
    area: [getPosition(), getPosition(), getPosition(), getPosition()],
    posLine: getPosLine(),
    ...(item || {}),
  };
};

export const apiGetDemoList = ({ pageSize, current }) => {
  return new Promise<any>((resolve) => {
    const total = pageSize * current;
    const data = [...Array(10)].map(() => {
      return getItem();
    });

    setTimeout(() => {
      resolve({
        code: '200',
        data: {
          rows: data,
          total,
        },
      });
    }, 1000);
  });
};

export const apiGetDemoDetail = (item: any = {}) => {
  return new Promise<any>((resolve) => {
    setTimeout(() => {
      resolve({
        code: '200',
        data: {
          ...getItem(item),
          ...item,
        },
      });
    }, 1000);
  });
};
